/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.generic;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.Serializable;
import javax.swing.JTable;
import model.generic.TableModelWithListeners;

/**
 *
 * @author Dirk
 */
public class TableWithListeners extends JTable implements KeyListener{

    private TableModelWithListeners model;

    public TableWithListeners(TableModelWithListeners model) {
        this.model = model;
    }

    public TableWithListeners() {
    }
    
    public void setModel(TableModelWithListeners model){
        this.model = model;
    }
    
    @Override
    public TableModelWithListeners getModel(){
        return model;
    }
    
    @Override
    public void keyTyped(KeyEvent e) {
        if(e.getKeyCode() == KeyEvent.VK_DELETE && this.getSelectedRow() > -1) 
            model.removeItem(this.getSelectedRow());

    }

    @Override
    public void keyPressed(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void keyReleased(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
